package br.upis.pf1.dao;

import java.io.Serializable;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import br.upis.pf1.entity.Login;
import br.upis.pf1.util.HibernateUtil;

public class LoginDAO implements Serializable {

	private Session session;

	public LoginDAO() {
		this.session = HibernateUtil.getSession();
	}

	public Login logar(Login login) {
		Criteria c = this.session.createCriteria(Login.class);

		try {
			Login l = (Login) c.add(Restrictions.eq("login", login.getLogin()))
					.add(Restrictions.eq("senha", login.getSenha())).uniqueResult();
			
			if (l != null) {
				return l;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return null;
	}

}
